TREES

Trillions

The Treemap

Photo by Marc Babin on Unsplash

Photo by Marc Babin on Unsplash

One of the simplest ways to get an idea of one trillion dollars is to consider the amount in terms of the passage of time.
One trillion seconds equals thirty-two thousand years…
— Geoff Davis


Ingest the data

trillions for what

# Load data
df = read.csv("./archetypes/trillions/trillions.csv", header = TRUE, stringsAsFactors = FALSE)  # read text file 
df

Wrangle the data

factor category for color mapping

df_wrangle <- df
df_wrangle$category <- factor(df_wrangle$category)
df_wrangle

The Layout

squarified with size and fill

category_palette <- c(
  'helping' = '#4FC3F7',
  'hoarding' = '#00BCD4',
  'earning' = '#26A69A',
  'losing' = '#FF7043',
  'fighting' = '#F44336',
  'spending' = '#FBC02D',
  'saving' = '#8BC34A',
  'owing' = '#FF9800',
  'banking' = '#66BB6A',
  'winning' = '#5C6BC0'
)

# Layouts
# squarified" (the default), "scol", "srow" or "fixed"
# Simple
v1 <- ggplot(df_wrangle, aes(area = trillion_usd, fill = category)) +
  geom_treemap(color = "#ffffff") +
  scale_fill_manual(values = category_palette) +
  theme_minimal() +
  theme(legend.position = "bottom")

girafe(ggobj = v1, width_svg = 1280/72, height_svg = 720/72,
       options = list(opts_sizing(rescale = TRUE, width = 1.0))
)

with labels

# Labeled
v2 <- ggplot(df_wrangle, aes(area = trillion_usd, fill = category, label = what)) +
  geom_treemap(color = "#ffffff") +
  geom_treemap_text(fontface = "italic", colour = "white", place = "centre", grow = TRUE) +
  scale_fill_manual(values = category_palette) +
  theme_minimal() +
  theme(legend.position = "bottom")

girafe(ggobj = v2, width_svg = 1280/72, height_svg = 720/72,
       options = list(opts_sizing(rescale = TRUE, width = 1.0))
)

with labels and subgroups

# Sub-grouping
v3 <- ggplot(df_wrangle, aes(area = trillion_usd, fill = category, label = what,
                subgroup = category)) +
  geom_treemap(color = "#ffffff") +
  geom_treemap_subgroup_border(colour = "white") +
  geom_treemap_subgroup_text(place = "centre", grow = T, alpha = 0.5, colour =
                               "black", fontface = "italic", min.size = 0) +
  geom_treemap_text(colour = "white", place = "topleft", reflow = T) +
  scale_fill_manual(values = category_palette) +
  theme_minimal() +
  theme(legend.position = "bottom")

# v3

girafe(ggobj = v3, width_svg = 1280/72, height_svg = 720/72,
       options = list(opts_sizing(rescale = TRUE, width = 1.0))
)

References

citations for narrative and data sources